package fragment;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.baoyz.swipemenulistview.SwipeMenuListView;
import com.lanou.horo.myapplication.R;
import com.lanou.horo.myapplication.dbdao.RecommendDbEntity;

import java.util.ArrayList;
import java.util.List;

import dbdao.RecommendDBHelper;
import entity.FocusEntity;
import utils.adapter.CollectionAdpter;
import utils.adapter.FocusonAdpter;
import volley.VolleySingleton;

/**
 * 收藏 fragmnet
 * Created by dllo on 15/11/17.
 */
public class CollectionPageFragment extends AbsBaseFragment{
    private SwipeMenuListView listView;
    private CollectionAdpter adpter;
    private RecommendDBHelper helper;
    private LayoutInflater inflater;
    @Override
    protected int getLayoutView() {

        return R.layout.fragment_page_collection;
    }

    @Override
    protected void initView() {
        inflater =getActivity(). getLayoutInflater();
        helper = RecommendDBHelper.getInstance();
        listView = findView(R.id.collectionRecylerView);
        adpter = new CollectionAdpter();
        listView.setAdapter(adpter);
    }


    @Override
    protected void initData() {

        adpter.setData(inflater, helper.queryAll());
        //点击跳转的监听  进入播放页面
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //得到当前的
                goToPlay(helper.queryAll().get(position).getUid());
            }
        });


        //长按删除的方法
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
               new AlertDialog.Builder(getContext())
                       .setTitle("删除")
                       .setMessage("确定要删除该关注吗")
                       .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                           @Override
                           public void onClick(DialogInterface dialog, int which) {

                           }
                       })
                       .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                           @Override
                           public void onClick(DialogInterface dialog, int which) {
                              helper.deleRecommendById(helper.queryAll().get(position).getId());
                               CollectionAdpter adpter = new CollectionAdpter();
                               adpter.setData(inflater,helper.queryAll());
                               listView.setAdapter(adpter);
                           }
                       }).create().show();


                return true;
            }
        });



    }



}
